﻿ 
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Aggregates;

namespace Sharp.Domain.PlatformBoundedContext.ModelConfigurations
{
    public partial class OrgForBusinessConfiguration
        : EntityTypeConfiguration<OrgForBusiness>
    {
        public OrgForBusinessConfiguration()
        { 
            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            Property(t => t.Title)
                .HasMaxLength(50)
                .IsOptional();
            Property(t => t.ParentId)
                .IsOptional();
            Property(t => t.Remark)
                .HasMaxLength(255)
                .IsOptional();
 
            Property(t => t.CheckInTime)
                .IsRequired();
            Property(t => t.CheckInUserId)
                .IsRequired();
            Property(t => t.ModifiTime)
                .IsOptional();
            Property(t => t.ModifiedUserId)
                .IsOptional();

            // Relationships
            HasOptional(t => t.ParentOrgForBusiness)
                .WithMany(t => t.ParentOrgForBusinesses)
                .HasForeignKey(d => d.ParentId);


            HasMany(t => t.People)
                .WithMany(t => t.OrgForBusinesses);

        }
    }
}

